<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数节流</title>
</head>

<body>
    <script>
        var lock = true;

        function func() {
            //如果锁是关闭状态 则不执行
            if (!lock) return;

            //函数核心语句
            //关锁
            lock = false;

            //指定毫秒数后将锁打开
            setTimeout(function () {
                lock = true;
            }, 2000)
        }
    </script>
</body>

</html>